package com.yuke.cloud.service.wmc.controller.frontend;

import com.yuke.cloud.common.util.wrapper.WrapMapper;
import com.yuke.cloud.common.util.wrapper.Wrapper;
import com.yuke.cloud.service.wmc.dto.WmsStockInOutDto;
import com.yuke.cloud.service.wmc.entity.WmsStockInOut;
import com.yuke.cloud.service.wmc.service.WmsStockInOutService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import com.yuke.cloud.common.core.support.BaseController;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by zn on 2020/11/06.
*/
@Api(value = "WEB - WmsStockInOutController", tags = "处理WmsStockInOut相关请求", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
@RequestMapping("/wms/stockInOut")
public class WmsStockInOutController extends BaseController {
    @Resource
    private WmsStockInOutService wmsStockInOutService;

    @PostMapping
    @ApiOperation(httpMethod = "POST", value = "新增一条记录")
    public Wrapper add(@ApiParam(name = "wmsStockInOut", value = "该数据记录的POJO") @RequestBody WmsStockInOut wmsStockInOut) {
        wmsStockInOutService.save(wmsStockInOut);
        return WrapMapper.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(httpMethod = "DELETE", value = "根据id删除一条记录")
    public Wrapper delete(@ApiParam(name = "id", value = "记录id") @PathVariable Long id) {
        wmsStockInOutService.deleteById(id);
        return WrapMapper.ok();
    }

    @PutMapping
    @ApiOperation(httpMethod = "PUT", value = "修改一条记录")
    public Wrapper update(@ApiParam(name = "wmsStockInOut", value = "需要修改的内容") @RequestBody WmsStockInOut wmsStockInOut) {
        wmsStockInOutService.update(wmsStockInOut);
        return WrapMapper.ok();
    }

    @GetMapping("/{id}")
    @ApiOperation(httpMethod = "GET", value = "根据ID获取具体信息")
    public Wrapper<WmsStockInOut> detail(@ApiParam(name = "id", value = "记录id") @PathVariable Long id) {
        WmsStockInOut wmsStockInOut = wmsStockInOutService.findById(id);
        return WrapMapper.ok(wmsStockInOut);
    }

    @GetMapping
    @ApiOperation(httpMethod = "GET", value = "分页获取所有记录")
    public Wrapper<PageInfo<WmsStockInOut>> list(@ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                    @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<WmsStockInOut> list = wmsStockInOutService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return WrapMapper.ok(pageInfo);
    }

//商品拆装
    @PostMapping("/partGoods")
    @ApiOperation(httpMethod = "POST", value = "商品拆装")
    public Wrapper partGoods(@ApiParam(name = "wmsStockInOut", value = "需要修改的内容") @RequestBody WmsStockInOut wmsStockInOut) {
        Integer num = wmsStockInOutService.partGoods(wmsStockInOut);
        return WrapMapper.ok(num);
    }

    //商品拆装的红冲
    @GetMapping("/deletePartGoods")
    @ApiOperation(httpMethod = "POST", value = "商品拆装")
    public Wrapper deletePartGoods(@ApiParam(name = "wmsStockInOut", value = "需要修改的内容") @RequestParam Long id) {
        Integer num = wmsStockInOutService.deletePartGoods(id);
        return WrapMapper.ok(num);
    }

    @PostMapping("/selectAndSpecName")
    @ApiOperation(httpMethod = "POST", value = "条件查询")
    public Wrapper<PageInfo<WmsStockInOut>> selectAndSpecName(@ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                 @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size,
                                                 @ApiParam(name = "wmsStockInOutDto", value = "查询条件") @RequestBody WmsStockInOutDto wmsStockInOutDto
                                                              ) {
        PageHelper.startPage(page, size);
        List<WmsStockInOutDto> list = wmsStockInOutService.selectAndSpecName(wmsStockInOutDto);
        PageInfo pageInfo = new PageInfo(list);
        return WrapMapper.ok(pageInfo);
    }


}
